package com.dataseek.iot.mysql.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.dataseek.iot.mysql.entity.User;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * @author cc
 * @Title: 自定义用户接口
 * @Description: 自定义用户接口
 * @date 2021/10/1912:27 下午
 * @since 1.0
 */
public interface MyUserMapper extends BaseMapper<User> {

    /**
     * 根据用户名密码查看所有数据
     * @return
     */
    //TODO 线路关联逻辑变化，需要大改
    @Select("SELECT r.role_inner_id as roleId  ,u.user_inner_id as userId,  r.role_name  as roleName,\n" +
            "r.role_code as roleCode ,r.menu_auth as menuAuth ,r.line_id as lineId , r.routes as routes, \n" +
            "r.district_id as districtId,u.username as username ,u.nickname as nickname ,u.used  as used, \n" +
            "u.password as password ,u.tel as tel, u.mail as mail, u.sex as sex ,u.avatar as avatar\n" +
            "from `role` r left join `user` u on u.role_id = r.role_inner_id\n"+
            "where username = #{username} and password = #{password}"
    )
    List<Map<String, Object>> selectAllUserDetails(@Param("username") String username, @Param("password") String password);

    /**
     * 根据用户名查看用户所有信息
     * @param username
     * @return
     */
    //TODO 线路关联逻辑变化，需要大改
    @Select("SELECT r.role_inner_id as roleId  ,u.user_inner_id as userId,  r.role_name  as roleName,\n" +
            "r.role_code as roleCode ,r.menu_auth as menuAuth ,r.line_id as lineId , r.routes as routes, \n" +
            "r.district_id as districtId,u.username as username ,u.nickname as nickname ,u.used  as used, \n" +
            " u.tel as tel, u.mail as mail, u.sex as sex ,u.avatar as avatar\n" +
            "from `role` r left join `user` u on u.role_id = r.role_inner_id\n"+
            "where username = #{username}"
    )
    List<Map<String, Object>> selectAllUserDetailsByUsername(@Param("username") String username);


}
